#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100005;
int main()
{
    int n, m, i, tmp, sum = 0, dis[maxn] = {0}, left, right;
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
    {
        scanf("%d", &tmp);
        sum += tmp;
        dis[i] = sum;
    }
    scanf("%d", &m);
    for (int i = 0; i < m; i++)
    {
        scanf("%d %d", &left, &right);
        if (left > right)
            swap(left, right);
        int tmp = dis[right - 1] - dis[left - 1];
        printf("%d\n", min(tmp, sum - tmp));
    }

    return 0;
}